#pragma once

#include "pch.h"

#include <stdarg.h>

// Default logfile path
#define DEFAULT_LOG_FILE L"C:\\Data\\Users\\System\\RootRpcServer.log"
// Event logging level
typedef enum _LOGGING_LEVEL {
	LOG_LEVEL_QUIET = 0,
	LOG_LEVEL_ERROR = 1,
	LOG_LEVEL_WARNING = 2,
	LOG_LEVEL_INFO = 3,
	LOG_LEVEL_VERBOSE = 4,
	LOG_LEVEL_DEBUG = 5,
	LOG_LEVEL_MAX
} LOGGING_LEVEL;
#define DEFAULT_LOG_LEVEL LOG_LEVEL_INFO

// What operation is the user asking us to perform?
typedef enum _OPERATION {
	OPERATION_UNKNOWN = 0,
	OPERATION_HELP,
	OPERATION_INSTALL,
	OPERATION_UPDATE,
	OPERATION_DELETE,
	OPERATION_START,
	OPERATION_STOP,
	OPERATION_QUERY,
	OPERATION_MAX
} OPERATION;

// Registry path for server
PCWSTR REGPATH = L"SOFTWARE\\NCC Group\\RootRpc";
PCWSTR LOGFILEVALUE = L"logfile";
PCWSTR LOGLEVELVALUE = L"loglevel";
PCWSTR DISPLAY_NAME = L"RootRPC Server";
#define SECURITYMANAGER_PATH L"SOFTWARE\\Microsoft\\SecurityManager"
#define CAPABILITIES_KEYPATH SECURITYMANAGER_PATH L"\\Capabilities"
#define CAPABILITYCLASSES_KEYPATH SECURITYMANAGER_PATH L"\\CapabilityClasses"
WCHAR THIRD_PARTY_CLASS[] = L"CAPABILITY_CLASS_THIRD_PARTY_APPLICATIONS\0";
PCWSTR SDDL_STRING = L"D:(A;;GA;;;SY)(A;;GA;;;BA)"	// SYSTEM and Administrators get full access
L"(A;;LCRP;;;" ID_CAP_ROOTRPC_APP_STRING L")"	// ID_CAP_ROOTRPC can query and start
L"(A;;LCRP;;;S-1-5-21-2702878673-795188819-444038987-1030)"
L"(A;;LCRP;;;" ID_CAP_ROOTRPC_SVC_STRING L")";
//PCWSTR SDDL_STRING = L"D:(A;;GA;;;SY)(A;;GA;;;BA)"	// SYSTEM and Administrators get full access
//L"(A;;LCRP;;;S-1-15-3-1024-"					// ID_CAP_EVERYONE can query and start
//L"3625662137-2682091254-856171984-2868379045-3001028726-1009205972-4175949866-684286152)"
//L"(A;;LCRP;;;S-1-5-21-2702878673-795188819-444038987-1030)"
//L"(A;;LCRP;;;S-1-5-21-2702878673-795188819-444038987-1031)";

DWORD WINAPI HandlerEx(DWORD dwControl, DWORD dwEventType, LPVOID lpEventData, LPVOID lpContext);
void WINAPI ServiceMain(DWORD argc, LPWSTR * argv);
void PrintHelp();
WINERR InstallTheService();
WINERR UpdateTheService();
WINERR StartTheService();
WINERR StopTheService();
WINERR DeleteTheService();

WINERR CreateCapability();
WINERR InstallClients();

WINERR SetLogLevel(LOGGING_LEVEL level);
WINERR SetLogFile(LPWSTR lpszPath);
void SetLogPtrs();
